

let panel = document.querySelector(".panel")

//获取分类标题的数据
function ww() {
    fetch("http://chst.vip:1234/api/getbrandtitle")
        .then(response => response.json())
        .then(res => {
            let domstr = ''
            res.result.forEach(item => {
                domstr += `<div class="panel-heading" titleid=${item.brandTitleId} flag=0>
            <h3>${item.brandTitle}</h3>
            <i>▼</i>
        </div>
        <div class="panel-content hide">
            <ul>

            </ul>
        </div>`
            })
            panel.innerHTML = domstr
        })
        .then(res => {
            let panel_heading = document.querySelectorAll(".panel-heading")
            let panelObj = { ...panel_heading }
        })

    for (let i = 0; i <= 52; i++) {
        fetch("http://chst.vip:1234/api/getbrand?brandtitleid=" + i)
            .then(response => response.json())
            .then(res => {
                let domStr = ''
                res.result.forEach(item => {
                    domStr += `
                    <li brandid=${item.brandId}>
                        <div class="icon">
                            <i>${1}</i><i>${item.brandName}</i>
                        </div>

                        <div class="sel">
                            ${item.brandInfo}
                        </div>
                    </li>
                    `
                })
                // console.log(domStr);
                $(".panel").children(".panel-content").eq(i).children('ul').html(domStr)
            })
    }


}
ww()



// 点击展开事件
// 0 是关闭，1 是打开
panel.addEventListener("click", function (e) {
    let _this = e.target
    let panel_content = $(".panel-content")
    if (_this.getAttribute("flag") === '0') {
        _this.setAttribute("flag", "1")
        if (_this.className = "panel-heading") {
            $(_this).next().slideDown(200)
            $(_this).next().siblings('div.panel-content.hide').slideUp(200)
            $(_this).siblings('div.panel-heading').attr("flag", "0")
        }
    } else if (_this.getAttribute("flag") === '1') {
        _this.setAttribute("flag", "0")
        if (_this.className = "panel-heading") {
            $(_this).next().slideUp(200)
            // $(_this).next().siblings('div.panel-content.hide').slideDown(200)
            // $(_this).siblings('div.panel-heading').attr("flag", "1")
        }
    }
})



//跳转事件
panel.addEventListener("click", function (e) {
    let _this = e.target;
    let brandid;
    if (_this.localName === "li") {
        brandid = _this.getAttribute("brandid")
        // console.log(categoryid);
        location.href = "./ppdqlist.html?brandid=" + brandid
    } else if (_this.className === "icon" || _this.className === "sel") {
        brandid = _this.parentNode.getAttribute("brandid")
        // console.log(categoryid);
        location.href = "./ppdqlist.html?brandid=" + brandid
    } else if (_this.localName === "i") {
        brandid = _this.parentNode.parentNode.getAttribute("brandid")
        // console.log(categoryid);
        location.href = "./ppdqlist.html?brandid=" + brandid
    }

})
